package ch03.demo.service;

import ch03.demo.IntermediarySubclass;
import ch03.demo.service.impl.RealBuyer;
import org.apache.log4j.Logger;

public class Main {
    private static Logger logger = Logger.getLogger(Main.class);

    public static void main(String[] args) {
        try {
//            NewsDao dao = SimpleDaoFactory.getInstance();
//            NewsServiceImpl service = new NewsServiceImpl();
//            service.setDao(dao);

//            NewsDao dao = SimpleDaoFactory.getInstance("mysql");
//            NewsServiceImpl service = new NewsServiceImpl();
//            service.setDao(dao);

//            AbstractFatory fatory=new MySqlDaoFactory();//改变具体工厂可创建不同产品
//            NewsDao dao=fatory.getInstance();
//            NewsServiceImpl service=new NewsServiceImpl();
//            service.setDao(dao);

//            Buyer buyer=new IntermediaryImpl(new RealBuyer());
//            String result=buyer.havealook();
//            logger.debug(result);

            RealBuyer buyer=new IntermediarySubclass();
            String result=buyer.havealook();
            logger.debug(result);

//            Buyer buyer= IntermediaryJdkProxyFactory.create(new RealBuyer());
//            String result=buyer.havealook();
//            logger.debug(result);

//            RealBuyer buyer= IntermediaryCglibProxyFactory.create(RealBuyer.class);
//            String result=buyer.havealook();
//            logger.debug(result);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
